/*
* © 2010 Autodata Solutions Company. All Rights Reserved
* This source code is the confidential and proprietary information of Autodata Solutions Company.
* The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
* without the prior written consent of Autodata Solutions Company.
*/
Ext.ns('net.autodata.compare.photos');
(function () {
	
	/**
	 * @class VehiclePhotosPanel
	 * @extends Ext.BoxComponent
	 * @namespace net.autodata.compare.photos
	 */
	var Panel = Ext.extend(Ext.BoxComponent, {
		
		autoEl: {
			tag: 'div',
			cls: 'vehiclephotos-panel'
		},
		
		view: undefined,
		viewCfg: undefined,
		
		constructor: function () 
		{	
			this.store = new Ext.data.Store({
				autoLoad: false,
				reader: new Ext.data.JsonReader({
					idProperty: 'imageId',
					root: 'rows',					
					fields: [
					    {name: 'imageId'},
						{name: 'acode'},
						{name: 'shotId'},
						{name: 'imageName'},
						{name: 'imageType'}
					]
				})
			});
			
			this.addEvents({'viewlarger': true});
			
			Panel.superclass.constructor.apply(this, arguments);
		},
		
		initComponent: function ()
		{
			Panel.superclass.initComponent.apply(this, arguments);
			var view = this.getView();
			view.init(this);
			
			this.store.on('load', this.onLoad, this);
		},
		
		getView: function ()
		{
			if (!this.view) {
				this.view = new net.autodata.compare.photos.VehiclePhotosView(this.viewCfg);
			}
			return this.view;
		},
		
		getStore: function ()
		{
			return this.store;
		},
		
		/**
		 * @private
		 */
		onLoad: function ()
		{
			var view = this.getView();
			view.refresh();
		},
		
		/**
		 * @private
		 */
		onRender: function ()
		{
			Panel.superclass.onRender.apply(this, arguments);
			var view = this.getView();
			view.render();
		},
		
		onDestroy: function ()
		{
			this.store.un('load', this.onLoad, this);
			Panel.superclass.onDestroy.apply(this, arguments);
		}
		
	});
	
	net.autodata.compare.photos.VehiclePhotosPanel = Panel;
})();